<template>
	<view class="flex center alcenter">
		<text v-if="myt >0">支付剩余时间：</text>
		<text v-if="myt >0">{{showTime}}</text>
		<text v-if="myt <= 0">支付超时，订单自动取消</text>
	</view>
</template>

<script>
	export default{
		props:{
			t:{
				type:Number,
				default:900,
			}
		},
		data(){
			return {
				myt:0,
				timer:null,
			}
		},
		computed:{
			showTime(){
				var i = Math.floor( this.myt / 60);
				var s = this.myt % 60;
				return i+'分'+s+'秒';
			}
		},
		methods:{
			djs(){
				this.timer = setInterval(()=>{
					if(this.myt <= 0){
						this.$emit('end',true);
						clearInterval(this.timer);
					}else{
						this.myt = this.myt - 1;
					}
				},1000);
			}
		},
		created(){
			this.myt = this.t;
			this.djs();
		},
		destroyed(){
			if(this.timer != null){
				clearInterval(this.timer);
			}
		}
	}
</script>

<style>
</style>
